const newsData = require('../../utils/newsData.js');

Page({
  data: {
    title: '',
    source: '',
    time: '',
    content: ''
  },

  onLoad(options) {
    const code = options.code;
    const id = parseInt(options.id);
    
    const newsList = newsData.getNewsByCode(code);
    const newsItem = newsList.find(item => item.id === id) || {};

    this.setData({
      title: newsItem.title || '未找到新闻',
      source: newsItem.source || '系统提示',
      time: newsItem.time || '--:--',
      content: newsItem.content || '该新闻内容不存在。'
    });

    wx.setNavigationBarTitle({
      title: newsItem.title || '新闻详情'
    });
  }
});
